package viettravel.guiandevent.place;

import java.util.ArrayList;

import viettravel.DAO.FriendDAO;
import viettravel.common.Constants;
import viettravel.guiandevent.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class FriendListsAdapter extends BaseAdapter {

	private ArrayList<FriendDAO> mFriendList;
	private Context mContext;
	
	public FriendListsAdapter(Context _context, ArrayList<FriendDAO> rowFriend){
		mFriendList = new ArrayList<FriendDAO>();
		mFriendList.addAll(rowFriend);
		mContext = _context;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mFriendList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mFriendList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View _view, ViewGroup _viewGroup) {
		// TODO Auto-generated method stub
		View view = _view;
		if (view == null){
			LayoutInflater layoutInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = layoutInflater.inflate(R.layout.row_friendlists, null);
        }
		
		FriendDAO l = mFriendList.get(position);
		ImageView friendAvatar = (ImageView)view.findViewById(R.id.friendAvatar);
		TextView friendName = (TextView)view.findViewById(R.id.friendName);
		TextView friendAddress = (TextView)view.findViewById(R.id.friendAddress);
		
		friendAvatar.setBackgroundDrawable(l.getDrawable());
		
		friendName.setTypeface(Constants.TYPEFACE_NYALA);
		friendName.setText(l.getName());
		
		friendAddress.setTypeface(Constants.TYPEFACE_NYALA);
		friendAddress.setText(l.getAddress());                      
		return view;
	}
}
